package com.example.performance.r2dbc.entity.performance;

import com.example.performance.r2dbc.entity.RecordDb;
import lombok.NonNull;
import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import static com.example.performance.r2dbc.entity.performance.RecordSetUtil.*;

/**
 * @author ShiSheng Gao
 * @since 2023/04/17
 */

public class AllRecordRowMapperByIndex implements RowMapper<RecordDb> {

    @Override
    public @NonNull RecordDb mapRow(@NonNull ResultSet rs, int rowNum) throws SQLException {
        return from(rs);
    }

    private RecordDb from(ResultSet rs) throws SQLException {
        Long id = getLong(rs, 1);
        Long nodeId = getLong(rs, 2);
        String commandeId = getString(rs, 3);
        String clientId = getString(rs, 4);
        Double commandeQty = getDouble(rs, 5);
        Long expedDemand = getLong(rs, 6);
        Long dluo = getLong(rs, 7);
        Long prod = getLong(rs, 8);
        Double livre = getDouble(rs, 9);
        Long livraison = getLong(rs, 10);
        Long prodInit = getLong(rs, 11);
        Double reliquat = getDouble(rs, 12);
        Integer statut = getStatus(rs, 13);
        String text1 = getString(rs, 16);
        String text2 = getString(rs, 17);
        String text3 = getString(rs, 18);
        String text4 = getString(rs, 19);
        String text5 = getString(rs, 20);
        String text6 = getString(rs, 21);
        String text7 = getString(rs, 22);
        String text8 = getString(rs, 23);
        String text9 = getString(rs, 24);
        String text10 =getString(rs, 25);
        Double qty1 = getDouble(rs, 26);
        Double qty2 = getDouble(rs, 27);
        Double qty3 = getDouble(rs, 28);
        Double qty4 = getDouble(rs, 29);
        Double qty5 = getDouble(rs, 20);
        Double qty6 = getDouble(rs, 31);
        Double qty7 = getDouble(rs, 32);
        Double qty8 = getDouble(rs, 33);
        Double qty9 = getDouble(rs, 34);
        Double qty10 =getDouble(rs, 35);
        Long date1 = getLong(rs, 36);
        Long date2 = getLong(rs, 37);
        Long date3 = getLong(rs, 38);
        Long date4 = getLong(rs, 39);
        Long date5 = getLong(rs, 40);
        Long date6 = getLong(rs, 41);
        Long date7 = getLong(rs, 42);
        Long date8 = getLong(rs, 43);
        Long date9 = getLong(rs, 44);
        Long date10 =getLong(rs, 45);
        return RecordDb.builder().nodeId(nodeId).id(id).commandeId(commandeId).clientId(clientId).commandQty(commandeQty).expedDemand(expedDemand)
                .dluo(dluo).prod(prod).livre(livre).livraison(livraison).prodInit(prodInit).reliquat(reliquat).text1(text1).text2(text2)
                .text3(text3).text4(text4).text5(text5).text6(text6).text7(text7).text8(text8).text9(text9).text10(text10)
                .qty1(qty1).qty2(qty2).qty3(qty3).qty4(qty4).qty5(qty5).qty6(qty6).qty7(qty7).qty8(qty8).qty9(qty9).qty10(qty10)
                .date1(date1).date2(date2).date3(date3).date4(date4).date5(date5).date6(date6).date7(date7).date8(date8).date9(date9)
                .date10(date10).statut(statut).build();
    }

}
